/*
 * @Description: ------------ fileDescription -----------
 * @Author: snows_l snows_l@163.com
 * @Date: 2024-08-11 12:04:39
 * @LastEditors: snows_l snows_l@163.com
 * @LastEditTime: 2024-10-31 10:50:19
 * @FilePath: /blog/src/api/article.ts
 */
import request from '@/utils/request';

interface ItemArticle {
  id: number;
  title: string;
  author: string;
  createTime: string;
  updateTime: string;
  readCount: number;
  commentCount: number;
  shareCount: number;
  status: number;
  type: number;
  tags: string[];
  content: string;
  labels: string | string[];
  category: string;
  cover: string;
}

// 获取文章列表
export function getArticleList(data: { page: number; size: number; type?: string; label?: string }): Promise<{ code: number; data: ItemArticle[]; msg: string; total: number }> {
  return request({
    url: '/article/list',
    method: 'get',
    params: data
  });
}

// 获取文章详情
export function getArticleDetail(id: string) {
  return request({
    url: '/article/detail/' + id,
    method: 'get'
  });
}

// 新增评论数量
export function addCommentCount(id) {
  return request({
    url: '/article/commentCount',
    data: {
      id: id
    },
    method: 'put'
  });
}

// 新增分享次数
export function addShareCount(id) {
  return request({
    url: '/article/shareCount',
    data: {
      id: id
    },
    method: 'put'
  });
}

// 预览文章的html代码
export function previewArticleCodeToHtml(id) {
  return request({
    url: '/article/preview/' + id,
    method: 'get'
  });
}

// 获取访问量前三的文章
export function getTopArticle(size: number = 3) {
  return request({
    url: '/article/topRead',
    method: 'get',
    params: {
      size
    }
  });
}
